package net.cyndeline.scalarlib.rldrawing.rectangularFloorPlan.help

import net.cyndeline.scalarlib.rldrawing.rectangularFloorPlan.{FloorIntersection, RoomArea}
import net.cyndeline.scalarlib.rldrawing.util.Direction._

/**
 * Reduces a single rectangle in a floor plan down to its target size, if doing so is possible without breaking
 * adjacency constraints and maximum aspect ratios.
 *
 * A segment of a rectangle R (not a maximal segment) can only be moved inwards if it does not connect to any neighbors
 * of R. Thus every such segment is a candidate for reducing the rectangles size. Since every area represented by a
 * vertex has a minimum of one neighbor (unless specified as an exception by the user), at most three segments can
 * be moved per rectangle.
 *
 * Algorithm description:
 *
 *  1. Every segment available for moving is computed
 *  1. If there are neighbors connecting to the segments on the opposite axis, the furthest away coordinates of the
 *  intersections closest to the segments current position on both those axises are computed. The segment can never
 *  move past that, as doing so would break adjacency. A one coordinate margin must also be kept between the segment
 *  and the intersection to avoid diagonal holes between walls.
 *  1. While the target size has not been reached, the segments still able to move without hitting an adjacency
 *  constraint or the maximum aspect ratio are moved 1 step. If this involves more than one segment, the shortest
 *  one is prioritized to reach a 1:1 aspect ratio if possible.
 *  1. If the target size is met, or if every segment hits an adjacency constraint, or if the only segments capable
 *  to move cannot do so without hitting the maximum aspect ratio, Exit.
 *
 * @param maxAspectRatio The highest allowed ratio discrepancy between sides in rectangles.
 */
class RectangleScaler(maxAspectRatio: Double) {

  //TODO implement
  /*
   * Note: För att förhindra att ingångar skjuts in, räcker det med att markera dem så att de har en koppling på den yttre kanten.
   */
  def scaleDown[V](area: RoomArea[V], targetSize: Int, intersections: Vector[FloorIntersection[V]]): RoomArea[V] = {
    val directionsWithNoNeighbors = Set(North, South, West, East) diff intersections.map(_.direction).toSet
    null
  }

  private class SegmentToMove(startCord: Int, val directionToMove: Direction, val maxCoordinate: Int) {
    var coordinate = startCord
  }
}
